
package es.udc.emarketapp.emarket.model.admin.dao;

import es.udc.fbellas.j2ee.util.configuration.ConfigurationParametersManager;
import es.udc.fbellas.j2ee.util.exceptions.InternalErrorException;

public final class SQLAdminDAOFactory {
    
    private final static String DAO_CLASS_NAME_PARAMETER = 
	"SQLAdminDAOFactory/daoClassName";

    private final static Class daoClass = getDAOClass();
    
    private SQLAdminDAOFactory(){}
    
    private static Class getDAOClass(){
	
	Class concreteClass = null;
	
	try {
	    String daoClassName = 
		ConfigurationParametersManager.getParameter(
			DAO_CLASS_NAME_PARAMETER);
	    concreteClass = Class.forName(daoClassName);
	} catch (Exception e) {
	    e.printStackTrace();
	}
	
	return concreteClass;
    }
    
    public static SQLAdminDAO getDAO() throws InternalErrorException{
	
	try {
	    return (SQLAdminDAO) daoClass.newInstance();
	} catch (Exception e) {
	    String err = e.getMessage() + "Error In: SQLAdminDAOFactory";
	    throw new InternalErrorException(e);
	}
    }

}
